function [c, pVector,flag] = isArbitrage( A, z )
%isArbitrage
% This function determins if there exists arbitrage by checking the 
% state price vector where every entry is greater than 0
% Return Value: c: max of phi
%               pVector: Price Vector, ie Phi
%               flag: resulting flag of linprog

[scenarios nAsset] =size(A);
% Modify the constratins for linprog
Aeq = [A',zeros(scenarios,1);zeros(1,nAsset),0];
Beq = [z;0];
AIneq = repmat([zeros(1,scenarios),1],scenarios,1) - ...
    [eye(scenarios),zeros(scenarios,1)];
AIneq = [AIneq;zeros(1,scenarios),1];
BIneq = [zeros(scenarios,1);1e6];
 
f = [zeros(scenarios,1);-1];
[x,fval,flag,output,lambda] = linprog(f,AIneq,BIneq,Aeq,Beq);
pVector=x(1:scenarios);
c=x(scenarios+1);

end
